package com.tmeone.erpone.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tmeone.erpone.entity.Order;
import com.tmeone.erpone.mapper.OrderMapper;
import com.tmeone.erpone.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Autowired
    private OrderMapper orderMapper;


    @Override
    public IPage<Order> OrderPage(IPage<Order> page) {
        IPage<Order> orderIPage = orderMapper.OrderPage(page);
        orderIPage.getRecords().forEach(Order->{
            String orderId = Order.getOrderId();
            String statusByOrderId = orderMapper.getStatusByOrderId(orderId);
            Order.setStatus(statusByOrderId);
        });
        return orderIPage;
    }

    @Override
    public IPage<Order> selectOrderByOrderId(IPage<Order> page, String orderId) {
        IPage<Order> orderIPage = orderMapper.selectOrderByOrderId(page, orderId);
        orderIPage.getRecords().forEach(Order->{
            String statusByOrderId = orderMapper.getStatusByOrderId(orderId);
            Order.setStatus(statusByOrderId);
        });
        return orderIPage;
    }


}
